﻿using System;
using System.Web;
using System.Text;
using System.Text.RegularExpressions;
using System.Web.UI;
using WinnerCMS.Common.Security;
using Encoder = WinnerCMS.Common.Security.Encoder;
namespace WinnerCMS.Common
{
    /// <summary>
    /// 对话框类
    /// </summary>
    public class MsgBox
    {
        #region 提示框
        /// <summary>
        /// 提示框
        /// </summary>
        /// <param name="msg">提示信息</param>
        /// <param name="upName"></param>
        public static void Message(string msg, UpdatePanel upName)
        {
            if (upName == null) return;
            ScriptManager.RegisterStartupScript(upName, typeof(UpdatePanel), "AjaxMessage", string.Format("$().message(\"{0}\");", Encoder.JavaScriptEncode(msg)), true);
        }
        /// <summary>
        /// 提示框
        /// </summary>
        /// <param name="msg">提示信息</param>
        /// <param name="page">this</param>
        /// <returns>警告框JS</returns>
        public static void Message(string msg, Page page)
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), "AjaxMessage", string.Format("$().message(\"{0}\");", Encoder.JavaScriptEncode(msg)), true);
        }
        /// <summary>
        /// 一个含有“确定”，点击以后就转到预设网址的警告框
        /// </summary>
        /// <param name="msg">警告字串</param>
        /// <param name="url">“确定”以后要转到预设网址</param>
        /// <param name="upName"></param>
        public static void Message(string msg, string url, UpdatePanel upName)
        {
            string strScript = string.Format("$().message(\"{0}\"); window.location='{1}';", Encoder.JavaScriptEncode(msg), url);

            ScriptManager.RegisterStartupScript(upName, typeof(UpdatePanel), "AjaxMessage", strScript, true);
        }
        /// <summary>
        /// 一个含有“确定”，点击以后就转到预设网址的警告框
        /// </summary>
        /// <param name="msg">警告字串</param>
        /// <param name="url">“确定”以后要转到预设网址</param>
        /// <param name="page"></param>
        public static void Message(string msg, string url, Page page)
        {
            string strScript = string.Format("$().message(\"{0}\"); window.location='{1}';", Encoder.JavaScriptEncode(msg), url);

            page.ClientScript.RegisterStartupScript(page.GetType(), "AjaxMessage", strScript, true);
        }
        #endregion


        #region 警告框
        /// <summary>
        /// 警告框
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="page"></param>
        public static void Alert(string msg, Page page)
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), "Alert", string.Format("alert('{0}');", Encoder.JavaScriptEncode(msg)), true);
        }
    
        #endregion

         

    }
}